package com.c1802.dao.Impl;

import com.c1802.dao.LeaveDao;
import com.c1802.entity.Leave_Word;
import com.c1802.util.AliPool;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

public class LeaveDaoImpl implements LeaveDao {
    QueryRunner runner = new QueryRunner();
    @Override
    public List<Leave_Word> Leavefind() throws SQLException {
        String sql="select * from leave_word";
        Connection conn= AliPool.getConn();
        List<Leave_Word> list=runner.query(conn,sql,new BeanListHandler<Leave_Word>(Leave_Word.class));
        conn.close();
        return list;
    }

    @Override
    public int add(String user_name,String user_img, String ly) throws SQLException {
        String sql="insert into leave_word value(null,?,?,?,0)";
        Connection conn=AliPool.getConn();
        int num=runner.update(conn,sql,user_name,user_img,ly);
        conn.close();
        return num;
    }

    @Override
    public int update(int zan, int leave_id) throws SQLException {
        String sql="update leave_word set endorse=? where id=?";
        Connection conn=AliPool.getConn();
        int num=runner.update(conn,sql,zan,leave_id);
        conn.close();
        return num;
    }
}
